import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import menu from './modules/menu'
import role from './modules/role'
import manger from './modules/manger'
import cate from './modules/cate'
import specs from './modules/specs'
import member from './modules/member'
import goods from './modules/goods'
import seck from './modules/seck'
import banner from './modules/banner'
export default new Vuex.Store({
  state: {
    userinfo: sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo')) : null
  },
  getters: {
    getUserinfo(state) {
      return state.userinfo
    }
  },
  mutations: {
    REQ_USER(state, payLoad) {
      if (payLoad) {     
        state.userinfo = payLoad
        //将登录结果存储到本地：
        sessionStorage.setItem('userinfo',JSON.stringify(payLoad))
      }else{
        sessionStorage.removeItem('userinfo')
      }

    }
  },
  actions: {
    changeUser({ commit }, payLoad) {
      commit('REQ_USER', payLoad)
    }
  },
  modules: {
    menu,
    role,
    manger,
    cate,
    specs,
    member,
    goods,
    seck,
    banner
  }
})
